package com.csxy.yuekaiyeye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.yuekaiyeye.entity.EduTeacher;
import com.csxy.yuekaiyeye.entity.vo.TeacherQuery;
import com.csxy.yuekaiyeye.mapper.EduTeacherMapper;
import com.csxy.yuekaiyeye.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
    @Autowired
    private EduTeacherMapper eduTeacherMapper;

    @Override
    public Page<EduTeacher> getPageList(Page<EduTeacher> page, String name) {
        // 这里可以根据name做条件查询，暂时用null表示无条件
        baseMapper.selectPage(page, null);
        return page;
    }

    @Override
    public void pageQuery(Page<EduTeacher> pageParam, TeacherQuery teacherQuery) {
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        if (teacherQuery == null) {
            eduTeacherMapper.selectPage(pageParam, null);
        }
        if (teacherQuery.getName() != null && !"".equals(teacherQuery.getName())) {
        }
        if (teacherQuery.getLevel() != null && !"".equals(teacherQuery.getLevel())) {
            queryWrapper.eq("level", teacherQuery.getLevel());
        }
        if (teacherQuery.getBegin() != null && !"".equals(teacherQuery.getBegin())) {
            queryWrapper.ge("gmt_create", teacherQuery.getBegin());
            if (teacherQuery.getEnd() != null && !"".equals(teacherQuery.getEnd())) {
                queryWrapper.le("gmt_modified", teacherQuery.getEnd());
            }
            eduTeacherMapper.selectPage(pageParam, queryWrapper);
        }
    }
}
